package com.xianyuwangyou.taizhangdengji.ui

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.foundation.shape.RoundedCornerShape

/**
 * 自定义弹窗模板
 * 样式要求：
 * - 直角矩形
 * - 纯白背景
 * - 提示文字纯黑色
 * - 按钮文字颜色为#019883
 */
@Composable
fun CustomDialog(
    onDismissRequest: () -> Unit,
    title: String,
    message: String,
    confirmText: String = "确认",
    onConfirm: () -> Unit,
    dismissText: String = "取消",
    onDismiss: () -> Unit = onDismissRequest
) {
    Dialog(onDismissRequest = onDismissRequest) {
        Card(
            shape = RoundedCornerShape(0.dp),
            colors = CardDefaults.cardColors(
                containerColor = Color.White
            )
        ) {
            AlertDialog(
                onDismissRequest = onDismissRequest,
                title = {
                    Text(
                        text = title,
                        color = Color.Black,
                        style = TextStyle(fontSize = 18.sp)
                    )
                },
                text = {
                    Text(
                        text = message,
                        color = Color.Black,
                        style = TextStyle(fontSize = 14.sp)
                    )
                },
                confirmButton = {
                    Button(
                        onClick = {
                            onConfirm()
                            onDismissRequest()
                        },
                        colors = ButtonDefaults.buttonColors(
                            containerColor = Color.White
                        )
                    ) {
                        Text(
                            text = confirmText,
                            color = Color(0xFF019883)
                        )
                    }
                },
                dismissButton = {
                    Button(
                        onClick = {
                            onDismiss()
                            onDismissRequest()
                        },
                        colors = ButtonDefaults.buttonColors(
                            containerColor = Color.White
                        )
                    ) {
                        Text(
                            text = dismissText,
                            color = Color(0xFF019883)
                        )
                    }
                },
                containerColor = Color.White,
                shape = RoundedCornerShape(0.dp)
            )
        }
    }
}

/**
 * 简化版确认弹窗（只有确认按钮）
 */
@Composable
fun ConfirmDialog(
    onDismissRequest: () -> Unit,
    title: String,
    message: String,
    confirmText: String = "确认",
    onConfirm: () -> Unit
) {
    Dialog(onDismissRequest = onDismissRequest) {
        Card(
            shape = RoundedCornerShape(0.dp),
            colors = CardDefaults.cardColors(
                containerColor = Color.White
            )
        ) {
            AlertDialog(
                onDismissRequest = onDismissRequest,
                title = {
                    Text(
                        text = title,
                        color = Color.Black,
                        style = TextStyle(fontSize = 18.sp)
                    )
                },
                text = {
                    Text(
                        text = message,
                        color = Color.Black,
                        style = TextStyle(fontSize = 14.sp)
                    )
                },
                confirmButton = {
                    Button(
                        onClick = {
                            onConfirm()
                            onDismissRequest()
                        },
                        colors = ButtonDefaults.buttonColors(
                            containerColor = Color.White
                        )
                    ) {
                        Text(
                            text = confirmText,
                            color = Color(0xFF019883)
                        )
                    }
                },
                containerColor = Color.White,
                shape = RoundedCornerShape(0.dp)
            )
        }
    }
}